//
//  NaviSpeedView.m
//  one_buy_guizhou_ios
//
//  Created by xu yao on 2021/2/2.
//  Copyright © 2021 杨帅. All rights reserved.
//

#import "NaviSpeedView.h"
#import "UIView+Extension.h"

@interface NaviSpeedView()

@property (nonatomic, strong) UILabel *unitLabel;

@end

@implementation NaviSpeedView

+ (instancetype)speedView:(CGPoint)point {
    NaviSpeedView *speedView = [[NaviSpeedView alloc] initWithFrame:CGRectMake(point.x, point.y, 64, 64)];
    return speedView;;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 32;
        self.layer.borderColor = [UIColor colorWithRed:1 green:71.0/255.0 blue:0 alpha:1].CGColor;
        self.layer.borderWidth = 3.5;
        [self setupUI];
        
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.speedLabel];
    [self addSubview:self.unitLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.speedLabel sizeToFit];
    self.speedLabel.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    self.speedLabel.top -= 6;
    
    [self.unitLabel sizeToFit];
    self.unitLabel.centerX = self.speedLabel.centerX;
    self.unitLabel.top = self.speedLabel.bottom;
    
}

#pragma mark 懒加载
- (UILabel *)speedLabel{
    if (!_speedLabel) {
        _speedLabel = [[UILabel alloc] init];
        _speedLabel.textColor = [UIColor colorWithRed:1 green:71.0/255.0 blue:0 alpha:1];
        _speedLabel.font = [UIFont systemFontOfSize:30 weight:UIFontWeightSemibold];
        _speedLabel.text = @"0";
    }
    return _speedLabel;
}

- (UILabel *)unitLabel{
    if (!_unitLabel) {
        _unitLabel = [[UILabel alloc] init];
        _unitLabel.textColor = [UIColor colorWithRed:1 green:71.0/255.0 blue:0 alpha:1];
        _unitLabel.font = [UIFont systemFontOfSize:10];
        _unitLabel.text = @"km/h";
    }
    return _unitLabel;;
}
@end
